using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DataAccess;
using Entity; 
namespace Business
{
    public class bFeedBack
    {
        public static int insertFeedBack(eFeedBack feedback)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@CustomerID", SqlDbType.Int);
            pr.Value = feedback.CustomerID;
            paramList.Add(pr);

            pr = new SqlParameter("@Title", SqlDbType.NVarChar);
            pr.Value =feedback.Title;
            paramList.Add(pr);

            pr = new SqlParameter("@content", SqlDbType.NVarChar);
            pr.Value = feedback.content;
            paramList.Add(pr);

            pr = new SqlParameter("@Date", SqlDbType.DateTime);
            pr.Value = feedback.Date;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("insertFeedBack", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }
        public static int updateStatusFeedBack(int feedbackID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@FeedbackID", SqlDbType.Int);
            pr.Value = feedbackID;
            paramList.Add(pr);


            int r = dbh.ExecuteNonQuery("updateStatusFeedBack", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static int deleteFeedBack(int feedbackID)
        {
            DBHelper dbh = new DBHelper();

            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@FeedbackID", SqlDbType.Int);
            pr.Value = feedbackID;
            paramList.Add(pr);

            int r = dbh.ExecuteNonQuery("deleteFeedBack", CommandType.StoredProcedure, paramList);
            dbh.CloseConnection();
            return r;
        }

        public static DataTable getAllFeedBack()
        {
            DBHelper dbh = new DBHelper();
            DataTable dt = dbh.ExecuteQueryDataTable("getAllFeedBack", CommandType.StoredProcedure, new List<SqlParameter>());
            dbh.CloseConnection();
            return dt;
        }

        public static eFeedBack getFeedBackByID(int feedbackID)
        {
            IList<SqlParameter> paramList = new List<SqlParameter>();
            SqlParameter pr = new SqlParameter("@FeedbackID", SqlDbType.Int);
            pr.Value = feedbackID;
            paramList.Add(pr);

            IList il = bBase.LoadQueryString(typeof(eFeedBack), "getFeedBackByID", CommandType.StoredProcedure, paramList);
            if (il.Count > 0)
            {
                return (eFeedBack)il[0];
            }
            else
            {
                return null;
            }
        }
    }
}
